﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;



public partial class Control_HrInfonew : System.Web.UI.UserControl
{
    private Srvtools.WebDataSet WMasterHr;
    private int _eid;
    private bool _readonly;
    protected void Page_Load(object sender, EventArgs e)
    {


        if (!IsPostBack)
        {
            wnHr.Visible = !ReadOnly;

            InitializeComponent(true);
            WMasterHr.SetWhere("Employees.EmployeeId=" + Eid);

            MasterHr.DataSource = WMasterHr;

        }
        //int i = WMasterHr.GetRecordsCount();

    }



    public int Eid
    {
        get
        {
            return _eid;
        }
        set
        {
            _eid = value;
        }

    }

    public bool ReadOnly
    {
        get
        {
            return _readonly;
        }
        set
        {
            _readonly = value;
        }
    }




    private void InitializeComponent(bool action)
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Control_HrInfonew));
        this.WMasterHr = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMasterHr)).BeginInit();
        // 
        // WMasterHr
        // 
        this.WMasterHr.Active = action;
        this.WMasterHr.AlwaysClose = true;
        this.WMasterHr.DataCompressed = false;
        this.WMasterHr.DeleteIncomplete = true;
        this.WMasterHr.Guid = null;
        this.WMasterHr.LastKeyValues = null;
        this.WMasterHr.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMasterHr.PacketRecords = 100;
        this.WMasterHr.Position = -1;
        this.WMasterHr.RemoteName = "SEmployees.EmployeesHr";
        this.WMasterHr.ServerModify = false;
        ((System.ComponentModel.ISupportInitialize)(this.WMasterHr)).EndInit();

    }


    protected void wnHr_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "cmdFirst" || e.CommandName == "cmdPrevious"
            || e.CommandName == "cmdNext" || e.CommandName == "cmdLast")
        {
            MasterHr.ExecuteSelect(FVHr);
            DataBind();
        }
        else if (e.CommandName == "cmdAdd")
        {
            MasterHr.ExecuteAdd(FVHr);
            DataBind();
        }
        else if (e.CommandName == "cmdDelete")
        {
            MasterHr.ExecuteSelect(FVHr);
            DataBind();
        }
        else if (e.CommandName == "cmdApply" && FVHr.AllValidateSucess)
        {

            MasterHr.ExecuteSelect(FVHr);
            DataBind();
        }

    }



    protected void FVHr_DataBound(object sender, EventArgs e)
    {
        try
        {
            WorkTime_DepartmentDList dptddl = FVHr.FindControl("DepartmentId") as WorkTime_DepartmentDList;
            Control_JobList jb = FVHr.FindControl("JobId") as Control_JobList;

            //WorkTime_DepartmentDList dptddl1 = FVHr.FindControl("DepartmentDList1") as WorkTime_DepartmentDList;
            //Control_JobList jb1 = FVHr.FindControl("JobList1") as Control_JobList;

            //WorkTime_DepartmentDList dptddl2 = FVHr.FindControl("DepartmentDList2") as WorkTime_DepartmentDList;
            //Control_JobList jb2 = FVHr.FindControl("JobList2") as Control_JobList;

            //WorkTime_DepartmentDList dptddl3 = FVHr.FindControl("DepartmentDList3") as WorkTime_DepartmentDList;
            //Control_JobList jb3 = FVHr.FindControl("JobList3") as Control_JobList;

            //WorkTime_DepartmentDList dptddl4 = FVHr.FindControl("DepartmentDList4") as WorkTime_DepartmentDList;
            //Control_JobList jb4 = FVHr.FindControl("JobList4") as Control_JobList;

            //WorkTime_DepartmentDList dptddl5 = FVHr.FindControl("DepartmentDList5") as WorkTime_DepartmentDList;
            //Control_JobList jb5 = FVHr.FindControl("JobList5") as Control_JobList;

            if (FVHr.CurrentMode == FormViewMode.ReadOnly)
            {
                dptddl.ShowTextOnly(MasterHr.CurrentRow["DepartmentId"].ToString());
                jb.ShowTextOnly(MasterHr.CurrentRow["JobId"].ToString());


                //dptddl1.ShowTextOnly(MasterHr.CurrentRow["PartTimeDepId1"].ToString());
                //jb1.ShowTextOnly(MasterHr.CurrentRow["PartTimeJobId1"].ToString());

                //dptddl2.ShowTextOnly(MasterHr.CurrentRow["PartTimeDepId2"].ToString());
                //jb2.ShowTextOnly(MasterHr.CurrentRow["PartTimeJobId2"].ToString());

                //dptddl3.ShowTextOnly(MasterHr.CurrentRow["PartTimeDepId3"].ToString());
                //jb3.ShowTextOnly(MasterHr.CurrentRow["PartTimeJobId3"].ToString());

                //dptddl4.ShowTextOnly(MasterHr.CurrentRow["PartTimeDepId4"].ToString());
                //jb4.ShowTextOnly(MasterHr.CurrentRow["PartTimeJobId4"].ToString());

                //dptddl5.ShowTextOnly(MasterHr.CurrentRow["PartTimeDepId5"].ToString());
                //jb5.ShowTextOnly(MasterHr.CurrentRow["PartTimeJobId5"].ToString());
            }
            else
            {
                dptddl.ddlSelectValue(MasterHr.CurrentRow["DepartmentId"].ToString());
                jb.ddlSelectValue(MasterHr.CurrentRow["JobId"].ToString());

                //string a = MasterHr.CurrentRow["PartTimeDepId1"].ToString()
                //dptddl1.ddlSelectValue(MasterHr.CurrentRow["PartTimeDepId1"].ToString());
                //jb1.ddlSelectValue(MasterHr.CurrentRow["PartTimeJobId1"].ToString());

                //dptddl2.ddlSelectValue(MasterHr.CurrentRow["PartTimeDepId2"].ToString());
                //jb2.ddlSelectValue(MasterHr.CurrentRow["PartTimeJobId2"].ToString());

                //dptddl3.ddlSelectValue(MasterHr.CurrentRow["PartTimeDepId3"].ToString());
                //jb3.ddlSelectValue(MasterHr.CurrentRow["PartTimeJobId3"].ToString());

                //dptddl4.ddlSelectValue(MasterHr.CurrentRow["PartTimeDepId4"].ToString());
                //jb4.ddlSelectValue(MasterHr.CurrentRow["PartTimeJobId4"].ToString());

                //dptddl5.ddlSelectValue(MasterHr.CurrentRow["PartTimeDepId5"].ToString());
                //jb5.ddlSelectValue(MasterHr.CurrentRow["PartTimeJobId5"].ToString());
            }

            TextBox HrRemark = FVHr.FindControl("HrRemark") as TextBox;

            string Remark = MasterHr.CurrentRow["HrRemark"].ToString();

            int index = MasterHr.CurrentRow["HrRemark"].ToString().IndexOf("%");

            HrRemark.Text = index == -1 ? Remark : Remark.Substring(0, index);


        }
        catch
        { }
    }

    protected void MasterHr_Updating(object sender, Srvtools.WebDataSourceUpdatingEventArgs e)
    {


        string Dpt = MasterHr.CurrentRow["DepartmentId"].ToString();
        string Job = MasterHr.CurrentRow["JobId"].ToString();


        WorkTime_DepartmentDList dptddl = FVHr.FindControl("DepartmentId") as WorkTime_DepartmentDList;
        Control_JobList jb = FVHr.FindControl("JobId") as Control_JobList;

        //WorkTime_DepartmentDList dptddl1 = FVHr.FindControl("DepartmentDList1") as WorkTime_DepartmentDList;
        //Control_JobList jb1 = FVHr.FindControl("JobList1") as Control_JobList;

        //WorkTime_DepartmentDList dptddl2 = FVHr.FindControl("DepartmentDList2") as WorkTime_DepartmentDList;
        //Control_JobList jb2 = FVHr.FindControl("JobList2") as Control_JobList;

        //WorkTime_DepartmentDList dptddl3 = FVHr.FindControl("DepartmentDList3") as WorkTime_DepartmentDList;
        //Control_JobList jb3 = FVHr.FindControl("JobList3") as Control_JobList;

        //WorkTime_DepartmentDList dptddl4 = FVHr.FindControl("DepartmentDList4") as WorkTime_DepartmentDList;
        //Control_JobList jb4 = FVHr.FindControl("JobList4") as Control_JobList;

        //WorkTime_DepartmentDList dptddl5 = FVHr.FindControl("DepartmentDList5") as WorkTime_DepartmentDList;
        //Control_JobList jb5 = FVHr.FindControl("JobList5") as Control_JobList;

        MasterHr.CurrentRow["DepartmentId"] = dptddl.SelectDepmanetId;
        //MasterHr.CurrentRow["PartTimeDepId1"] = dptddl1.SelectDepmanetId;
        //MasterHr.CurrentRow["PartTimeDepId2"] = dptddl2.SelectDepmanetId;
        //MasterHr.CurrentRow["PartTimeDepId3"] = dptddl3.SelectDepmanetId;
        //MasterHr.CurrentRow["PartTimeDepId4"] = dptddl4.SelectDepmanetId;
        //MasterHr.CurrentRow["PartTimeDepId5"] = dptddl5.SelectDepmanetId;

        MasterHr.CurrentRow["JobId"] = jb.SelectId;
        //MasterHr.CurrentRow["PartTimeJobId1"] = jb1.SelectId;
        //MasterHr.CurrentRow["PartTimeJobId2"] = jb2.SelectId;
        //MasterHr.CurrentRow["PartTimeJobId3"] = jb3.SelectId;
        //MasterHr.CurrentRow["PartTimeJobId4"] = jb4.SelectId;
        //MasterHr.CurrentRow["PartTimeJobId5"] = jb5.SelectId;

        string CurrentRemark = MasterHr.CurrentRow["HrRemark"].ToString().Replace("%", "％");


        if (Dpt != dptddl.SelectDepmanetId && Dpt != "0")
        {
            TextBox txtB = FVHr.FindControl("MoveRemark") as TextBox;


            e.UpdatingValues["HrRemark"] = CurrentRemark + "%" + Dpt + "%" + Job + "%" + txtB.Text;
        }



    }

   
}
